<template>
    <div>
        <van-nav-bar title="标题" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" />

        <van-search v-model="statusval" shape="round" placeholder="请输入搜索关键词" />


        <van-empty image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" image-size="80"
            description="空空如也" v-show="kongstatus"/>

        <div class="box">
            <van-cell-group >
                <van-cell v-for="item in qsearchApiData" :title="item.goods_name" />
            </van-cell-group>
        </div>

        <div class="history" v-show="hisstatus">
            <div class="hot">
                <h4>搜索热门</h4>
                <van-tag type="primary">游戏</van-tag>
                <van-tag type="primary">网盘</van-tag>
                <van-tag type="primary">我的</van-tag>
                <van-tag type="primary">衣服</van-tag>
                <van-tag type="primary">鞋子</van-tag>
            </div>
            <div class="his">
                <h4>搜索历史</h4>
                <van-tag type="primary">游戏</van-tag>
                <van-tag type="primary">网盘</van-tag>
                <van-tag type="primary">我的</van-tag>
                <van-tag type="primary">衣服</van-tag>
                <van-tag type="primary">鞋子</van-tag>
            </div>
        </div>
    </div>
</template>

<script setup>
 import {qsearchApi} from '@/api/api'
 import {ref,watch} from 'vue'
 import _ from 'lodash'
 let statusval=ref('')
 let qsearchApiData=ref([])
 let hisstatus=ref(true)
 let kongstatus=ref(false)

 watch(statusval,_.debounce(val=>{
   console.log(val.length);
   if(val.length==0){
    hisstatus.value=true
    kongstatus.value=false
   }
   else{
    hisstatus.value=false
    qsearchApi(val).then((res => {
    console.log('搜索数据', res);
    qsearchApiData.value = res.data.message
    if(res.data.message.length==0){
        kongstatus.value=true
    }
    else{
         kongstatus.value=false
    }

}))
   }
   
 },1000))

</script>

<style lang="scss" scoped></style>